package com.kaiyidiannao.activity.SecondHandHouse;

import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.*;
import com.kaiyi.diannao.net.AsyncHttpResponseParse;
import com.kaiyi.diannao.net.LoadDataHandler;
import com.kaiyi.diannao.net.RequestClient;
import com.kaiyidiannao.common.BaseActionBarActivity;
import com.kaiyidiannao.common.util.AppUtils;
import com.kaiyidiannao.common.util.UploadImageUtils;
import com.kaiyidiannao.data.DataCenter;
import com.kaiyidiannao.https.HttpUtils;
import com.kaiyidiannao.imagescale.ImageGalleryActivity;
import com.kaiyidiannao.main.R;
import com.kaiyidiannao.model.bean.SecondHandHouse;
import com.kaiyidiannao.model.bean.UserBean;
import com.kaiyidiannao.view.ActionBarView;
import com.kaiyidiannao.widget.LoadingDialog;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by mark on 2014/4/15.
 */
public class SecondHandHousePublish extends BaseActionBarActivity implements View.OnClickListener {

    private EditText secondHandHouseNameEdit, secondHandHouseSquareEdit, secondHandHousePriceEdit, secondHandHouseAgeLimitEdit, secondHandHouseCallEdit, introduceEdit;
    private ImageView upload;

    private ImageView mImg0;
    private ImageView mImg1;
    private ImageView mImg2;
    private ImageView mImg3;
    private ImageView mImg4;
    private ImageView mImg5;
    private ImageView mImg6;
    private ImageView mImg7;

    String name;
    String square;
    String price;
    String houseyear;
    String call;
    String introduce;
    private ArrayList<UserBean> userBeans = DataCenter.userLogin;
    private ArrayList<UserBean> userBeansList = DataCenter.userBeans;
    private int mIndex = 0;
    private LoadingDialog mLoadingDialog;

    private static final String IMAGE_FILE_NAME = "faceImage";
    private String[] mImagePaths = new String[8];

    private String[] items = new String[]{"选择本地图片", "拍照"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setFullScreen();
        setContentView(R.layout.secondhandhouse_publish);

        findActionBar();
        initDialog();
        findViewById();
        initImageListener();
        initListener();

        //隐藏软键盘和功能选项
        AppUtils.setupUI(findViewById(R.id.scrollviewhouse), this);
    }

    private void initDialog() {
        mLoadingDialog = new LoadingDialog(this);
        mLoadingDialog.setCancelable(true);
        mLoadingDialog.setCanceledOnTouchOutside(false);
        mLoadingDialog.setText("提交数据中...");
    }

    private void findViewById() {

        secondHandHouseNameEdit = (EditText) findViewById(R.id.secondHandHouseNameEdit);
        secondHandHouseSquareEdit = (EditText) findViewById(R.id.secondHandHouseSquareEdit);
        secondHandHousePriceEdit = (EditText) findViewById(R.id.secondHandHousePriceEdit);
        secondHandHouseAgeLimitEdit = (EditText) findViewById(R.id.secondHandHouseAgeLimitEdit);
        secondHandHouseCallEdit = (EditText) findViewById(R.id.secondHandHouseCallEdit);
        introduceEdit = (EditText) findViewById(R.id.introduceEdit);
        Intent intent = getIntent();

        if (intent.getStringExtra("flag") == null) {

        } else {
            Bundle bundle = intent.getExtras();
            if (bundle != null) {
                SecondHandHouse secondHandHouse = (SecondHandHouse) bundle.getSerializable("secondHandHouse");
                secondHandHouseNameEdit.setText(secondHandHouse.getTitle());
                secondHandHouseSquareEdit.setText(secondHandHouse.getArea());
                secondHandHousePriceEdit.setText(secondHandHouse.getPrice());
                secondHandHouseAgeLimitEdit.setText(secondHandHouse.getHouseyear());
                secondHandHouseCallEdit.setText(secondHandHouse.getTelephone());
                introduceEdit.setText(secondHandHouse.getIntroduce());
            }
        }

        mImg0 = (ImageView) findViewById(R.id.auction_upload_imageView);
        mImg1 = (ImageView) findViewById(R.id.auction_upload_imageView1);
        mImg2 = (ImageView) findViewById(R.id.auction_upload_imageView2);
        mImg3 = (ImageView) findViewById(R.id.auction_upload_imageView3);
        mImg4 = (ImageView) findViewById(R.id.auction_upload_imageView4);
        mImg5 = (ImageView) findViewById(R.id.auction_upload_imageView5);
        mImg6 = (ImageView) findViewById(R.id.auction_upload_imageView6);
        mImg7 = (ImageView) findViewById(R.id.auction_upload_imageView7);
    }

    private void initListener() {
        // 开始发送
        actionBarView.button_right_icon2.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // 开始提交商品###
                if (userBeansList.size() == 0) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(SecondHandHousePublish.this).setTitle("错误信息").setMessage("请完善您的用户信息").setPositiveButton("确定", null);
                    return;
                } else {
                    actionBarView.button_right_icon2.setEnabled(false);
                    cheakUpdate();
                }
            }
        });
    }

    private void initImageListener() {
        mImg0.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mIndex = 0;
                showDialogOrFullImage(mIndex);
            }
        });
        mImg1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mIndex = 1;
                showDialogOrFullImage(mIndex);
            }
        });
        mImg2.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mIndex = 2;
                showDialogOrFullImage(mIndex);
            }
        });
        mImg3.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mIndex = 3;
                showDialogOrFullImage(mIndex);
            }
        });
        mImg4.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mIndex = 4;
                showDialogOrFullImage(mIndex);
            }
        });
        mImg5.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mIndex = 5;
                showDialogOrFullImage(mIndex);
            }
        });
        mImg6.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mIndex = 6;
                showDialogOrFullImage(mIndex);
            }
        });
        mImg7.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mIndex = 7;
                showDialogOrFullImage(mIndex);
            }
        });
    }

    private void cheakUpdate() {
        //名称
        name = secondHandHouseNameEdit.getText().toString();
        if (isEmpty(name)) {
            showToast("名称不能为空");
            actionBarView.button_right_icon2.setEnabled(true);
            return;
        } else if (name.length() > 30 || name.length() < 3) {
            showToast("名称为3-30，不能输入空格");
            actionBarView.button_right_icon2.setEnabled(true);
            return;
        }

        // 面积
        square = secondHandHouseSquareEdit.getText().toString();
        if (isEmpty(square)) {
            showToast("面积不能为空");
            actionBarView.button_right_icon2.setEnabled(true);
            return;
        } else if (Integer.parseInt(square) > 1000 || Integer.parseInt(square) <= 0) {
            showToast("面积为0-1000平米");
            actionBarView.button_right_icon2.setEnabled(true);
            return;
        }

        // 价格
        price = secondHandHousePriceEdit.getText().toString();
        BigDecimal bigDecimal = null;
        try{
            bigDecimal = new BigDecimal(price);
        }catch (NumberFormatException e){

        }

        if (isEmpty(price)) {
            showToast("价格不能为空");
            actionBarView.button_right_icon2.setEnabled(true);
            return;
        }else if(bigDecimal.compareTo(BigDecimal.valueOf(0))<=0){
            showToast("价格应大于0");
            actionBarView.button_right_icon2.setEnabled(true);
            return;
        }

        // 房龄
        houseyear = secondHandHouseAgeLimitEdit.getText().toString();
        if (isEmpty(houseyear)) {
            showToast("房龄不能为空");
            actionBarView.button_right_icon2.setEnabled(true);
            return;
        }

        //判断房龄是否合理
        Date date = new Date();
        if (Integer.parseInt(houseyear) > 100 || Integer.parseInt(houseyear) <= 0) {
            showToast("房龄为0-100年");
            actionBarView.button_right_icon2.setEnabled(true);
            return;
        }

        //联系方式
        call = secondHandHouseCallEdit.getText().toString();
        if (isEmpty(call)) {
            showToast("联系方式不能为空");
            actionBarView.button_right_icon2.setEnabled(true);
            return;
        }

        //介绍
        introduce = introduceEdit.getText().toString();
        if (isEmpty(introduce)) {
            showToast("介绍不能为空");
            actionBarView.button_right_icon2.setEnabled(true);
            return;
        } else if (introduce.length() <= 2) {
            showToast("介绍字数应为2个以上");
            actionBarView.button_right_icon2.setEnabled(true);
            return;
        }

        Log.d("message_house", name + price + houseyear + introduce + call + square);

        if (mImagePaths[0] != null && !"".equals(mImagePaths[0]) && new File(mImagePaths[0]).exists()) {
            // 开始上传图片
            uploadImages(0);
        } else {
            // ##可以上传了
            startUpLoadData();

        }

    }

    private boolean isEmpty(String str) {
        if (str != null && !"".equals(str.trim())) {
            return false;
        }
        return true;
    }


    // 时间选择器
    private void showCalendars(final TextView textView) {
        Calendar c = Calendar.getInstance();
        new DatePickerDialog(SecondHandHousePublish.this, new DatePickerDialog.OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                // TODO Auto-generated method stub
                textView.setText(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth);
            }
        }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)).show();
    }

    // 上传图片
    private void showImageDialog() {
        new AlertDialog.Builder(this)
                .setTitle("上传图片")
                .setItems(items, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        switch (which) {
                            case 0:
                                Intent intentFromGallery = new Intent();
                                intentFromGallery.setAction(Intent.ACTION_GET_CONTENT);
                                intentFromGallery.setType("image/*"); // 设置文件类型
                                startActivityForResult(intentFromGallery, UploadImageUtils.IMAGE_REQUEST_CODE);
                                break;
                            case 1:
                                Intent intentFromCapture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                                // 判断存储卡是否可以用，可用进行存储
                                if (AppUtils.isExistSD()) {
                                    File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
                                    File file = new File(path + "/" + IMAGE_FILE_NAME + mIndex + ".png");
                                    if (!file.exists()) {
                                        file.getParentFile().mkdirs();
                                    }
                                    intentFromCapture.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                                }
                                startActivityForResult(intentFromCapture, UploadImageUtils.CAMERA_REQUEST_CODE);
                                break;
                        }
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).show();

    }

    private String savePhoto(Bundle bundle) {
        Bitmap bitmap;
        if (bundle != null) {
            bitmap = bundle.getParcelable("data");
        } else {
            return null;
        }

        FileOutputStream b = null;
        String pathPhoto = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + "/cache/";
        File file = new File(pathPhoto + IMAGE_FILE_NAME + mIndex + ".png");
        if (!file.exists()) {
            file.getParentFile().mkdirs();// 创建文件夹
        }
        try {
            b = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, b);// 把数据写入文件
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } finally {
            try {
                if (b != null) {
                    b.flush();
                    b.close();
                }
                return file.getAbsolutePath();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    private Bitmap bitmap;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        //结果码不等于取消时候
        if (resultCode != RESULT_CANCELED) {
            switch (requestCode) {
                case UploadImageUtils.IMAGE_REQUEST_CODE:
                    Log.e("switch",data.getData().toString());
                    String[] proj = { MediaStore.Images.Media.DATA };

                    Cursor actualimagecursor = managedQuery(data.getData(),proj,null,null,null);

                    int actual_image_column_index = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

                    actualimagecursor.moveToFirst();

                    String img_path = actualimagecursor.getString(actual_image_column_index);

                    File file = new File(img_path);
                    BitmapFactory.Options options1 =  new BitmapFactory.Options();
                    options1.inSampleSize = 4;
                    bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(),options1);
//                    UploadImageUtils.startPhotoZoom(MessagePublish.this, data.getData());
                    data.putExtra("data",bitmap);
                    Log.d("img_path",img_path);
                    data.putExtra("img_path",img_path);
                    savePath(data);
                    break;
                case UploadImageUtils.CAMERA_REQUEST_CODE:
                    if (AppUtils.isExistSD()) {
                        Log.e("SWITCH",data+"");
                        File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
                        File tempFile = new File(path + "/" +IMAGE_FILE_NAME + mIndex + ".png");
                        Log.e("switch",IMAGE_FILE_NAME + "－－－－" + mIndex);
//                        UploadImageUtils.startPhotoZoom(MessagePublish.this, Uri.fromFile(tempFile));
                        Log.e("Path",path.toString());
                        Log.e("tempFile",tempFile.getAbsolutePath()+"");
                        options1 =  new BitmapFactory.Options();
                        options1.inSampleSize = 4;
                        bitmap = BitmapFactory.decodeFile(tempFile.getAbsolutePath(),options1);
//                    UploadImageUtils.startPhotoZoom(MessagePublish.this, data.getData());
//                            data.putExtra("data",bitmap);
                        Log.d("img_path",tempFile.getAbsolutePath());
//                            data.putExtra("img_path",tempFile.getAbsolutePath());
                        picPath = tempFile.getAbsolutePath();
                        savePath(data);
                    } else {
                        Toast.makeText(SecondHandHousePublish.this, "未找到存储卡，无法存储照片！", Toast.LENGTH_LONG).show();
                    }
                    break;
                case UploadImageUtils.RESULT_REQUEST_CODE: //图片缩放完成后

                    break;
            }
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    String picPath;
    Drawable drawable = null;
    public void savePath(Intent data){
        if (data != null) {
            // 保存图片
            mImagePaths[mIndex] = savePhoto(data.getExtras());
            if( mImagePaths[mIndex] == null ) {
                Toast.makeText(this, "图片转换出错", Toast.LENGTH_SHORT).show();
                return;
            }
            Log.e("switch",mIndex + "-----" + data.getExtras());
            Log.e("switch",mImagePaths[mIndex] + "-----" );
            Drawable drawable = UploadImageUtils.getImageToView(data, SecondHandHousePublish.this);
            switch (mIndex) {
                case 0:
                    mImg0.setImageDrawable(drawable);
                    mImg1.setVisibility(View.VISIBLE);
                    break;
                case 1:
                    mImg1.setImageDrawable(drawable);
                    mImg2.setVisibility(View.VISIBLE);
                    break;
                case 2:
                    mImg2.setImageDrawable(drawable);
                    mImg3.setVisibility(View.VISIBLE);
                    break;
                case 3:
                    mImg3.setImageDrawable(drawable);
                    mImg4.setVisibility(View.VISIBLE);
                    break;
                case 4:
                    mImg4.setImageDrawable(drawable);
                    mImg5.setVisibility(View.VISIBLE);
                    break;
                case 5:
                    mImg5.setImageDrawable(drawable);
                    mImg6.setVisibility(View.VISIBLE);
                    break;
                case 6:
                    mImg6.setImageDrawable(drawable);
                    mImg7.setVisibility(View.VISIBLE);
                    break;
                case 7:
                    mImg7.setImageDrawable(drawable);
                    break;
                default:
                    break;
            }
        }else {
            // 保存图片
            mImagePaths[mIndex] = picPath;
            if( mImagePaths[mIndex] == null ) {
                Toast.makeText(this, "图片转换出错", Toast.LENGTH_SHORT).show();
                return;
            }
            Log.e("switch",mIndex + "-----" );
            Log.e("switch",mImagePaths[mIndex] + "-----" );
//            Drawable drawable = UploadImageUtils.getImageToView(data, MessagePublish.this);
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = 4;
            Bitmap photo = BitmapFactory.decodeFile(picPath, options);

            drawable = new BitmapDrawable(this.getResources(),photo);
            switch (mIndex) {
                case 0:
                    mImg0.setImageDrawable(drawable);
                    mImg1.setVisibility(View.VISIBLE);
                    break;
                case 1:
                    mImg1.setImageDrawable(drawable);
                    mImg2.setVisibility(View.VISIBLE);
                    break;
                case 2:
                    mImg2.setImageDrawable(drawable);
                    mImg3.setVisibility(View.VISIBLE);
                    break;
                case 3:
                    mImg3.setImageDrawable(drawable);
                    mImg4.setVisibility(View.VISIBLE);
                    break;
                case 4:
                    mImg4.setImageDrawable(drawable);
                    mImg5.setVisibility(View.VISIBLE);
                    break;
                case 5:
                    mImg5.setImageDrawable(drawable);
                    mImg6.setVisibility(View.VISIBLE);
                    break;
                case 6:
                    mImg6.setImageDrawable(drawable);
                    mImg7.setVisibility(View.VISIBLE);
                    break;
                case 7:
                    mImg7.setImageDrawable(drawable);
                    break;
                default:
                    break;
            }
        }
    }


    private void findActionBar() {
        actionBarView = (ActionBarView) findViewById(R.id.actionbar);
        actionBarView.setTitle("二手房发布");

        // upload = (ImageView)findViewById(R.id.upload);

        actionBarView.button_right_icon2.setVisibility(View.VISIBLE);
        actionBarView.button_right_icon2.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.positive_button));

    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }

    @Override
    public void onClick(View v) {

    }

    private void startUpLoadData() {
        RequestParams params = new RequestParams();
        params.put("mid", "28");
        params.put("action", "add");
        params.put("userid", userBeans.get(0).getUserid());
        params.put("post[catid]", DataCenter.secondHandHouse_category_id + "");
        params.put("post[title]", name);
        params.put("post[price]", price);
        params.put("post[houseyear]", houseyear);
        params.put("post[introduce]", introduce);
        params.put("post[telephone]", call);
        params.put("post[area]", square);

        for (int i = 0; i < mImagePaths.length; i++) {
            if (mImagePaths[i] != null && !"".equals(mImagePaths[i].trim())) {
                if (i == 0) {
                    params.put("post[thumb]", mImagePaths[i]);
                } else {
                    params.put("post[thumb" + i + "]", mImagePaths[i]);
                }
            }
        }

        System.out.println("params--->" + params.toString());

        RequestClient.post(this, "http://www.3tixa.com:8086/kaiyi/member/my.php", params, new AsyncHttpResponseHandler() {
            //192.168.29.135:8080
//www.3tixa.com:8086
            @Override
            public void onStart() {
                if (!mLoadingDialog.isShowing()) {
                    mLoadingDialog.show();
                }
            }

            @Override
            public void onSuccess(String content) {
                if (!HttpUtils.isConnected()) {
                    Log.d("==============", "-=-=-=-=-");
                    showToast(R.string.no_network);
                    return;
                } else {
                    Toast.makeText(SecondHandHousePublish.this, "发布成功", Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent(SecondHandHousePublish.this, SecondHandHouseActivity.class);
                    startActivity(intent);
                    finish();
                    System.out.println("content-->" + content);
                }
            }

            @Override
            public void onFailure(Throwable error, String content) {
                Toast.makeText(SecondHandHousePublish.this, "发布失败，请重试！", Toast.LENGTH_SHORT).show();
                actionBarView.button_right_icon2.setEnabled(true);
                return;
            }

            @Override
            public void onFinish() {
                actionBarView.button_right_icon2.setEnabled(true);
                if (mLoadingDialog != null) {
                    mLoadingDialog.dismiss();
                }
            }

        });
    }

    private void uploadImages(final int pos) {

        RequestParams params = new RequestParams();
        params.put("moduleid", "28");

        try {
            params.put("upalbum", new File(mImagePaths[pos]));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
//    	params.put("oldurl", values); 	// 需要判断

        RequestClient.post(this, "http://www.3tixa.com:8086/kaiyi/appupload.php", params, new AsyncHttpResponseParse(this, new LoadDataHandler() {

            @Override
            public void onStart() {
                mLoadingDialog.show();
            }

            @Override
            public void onSuccess(String data) {
                if (data != null) {
                    mImagePaths[pos] = data.substring(2, data.length() - 2);
                    System.out.println(pos + ":" + data.substring(2, data.length() - 2));
                }
                // 提交成功, 提交下一个
                if (pos < mImagePaths.length - 1) {
                    if (mImagePaths[pos + 1] != null && !"".equals(mImagePaths[pos + 1])) {
                        uploadImages(pos + 1);
                    } else {
                        // 图片上传完毕
                        /***开始上传信息**/
                        startUpLoadData();
                    }
                } else {
                    // 图片上传完毕
                    /***开始上传信息**/
                    startUpLoadData();
                }
            }

            @Override
            public void onFailure(Throwable error, String content) {
                // 失败重新提交
               // uploadImages(pos);
                mLoadingDialog.dismiss();
                Toast.makeText(SecondHandHousePublish.this, "发布失败，请重试！", Toast.LENGTH_SHORT).show();
                actionBarView.button_right_icon2.setEnabled(true);
                return;
            }

        }));
    }


    /**
     * 显示图片选择对话框，或者全屏浏览图片
     *
     * @param mIndex
     */
    private void showDialogOrFullImage(int mIndex) {
        if (mImagePaths == null || mImagePaths[mIndex] == null || TextUtils.isEmpty(mImagePaths[mIndex].trim())) {
            showImageDialog();
        } else {
            startFullImage(mIndex);
        }
    }

    /**
     * 开启全屏图片浏览
     *
     * @param defaultIndex
     */
    private void startFullImage(int defaultIndex) {
        Intent intent = new Intent(getApplicationContext(), ImageGalleryActivity.class);
        Bundle bundle = new Bundle();
        bundle.putInt("defaultIndex", defaultIndex);
        ArrayList<String> imgPaths = new ArrayList<String>();
        for (String path : mImagePaths) {
            if (!TextUtils.isEmpty(path)) {
                imgPaths.add(path);
            }
        }
        bundle.putStringArrayList("imgPaths", imgPaths);
        intent.putExtras(bundle);
        startActivity(intent);
    }
}
